<%-- 
    Document   : db1
    Created on : 2014/8/19, 下午 01:26:16
    Author     : Felix
--%>

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
        Class.forName("com.mysql.jdbc.Driver");//載入驅動程式類別
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb","root","root");//取得connection實作物件，是資料庫連線代表物件
        Statement st = con.createStatement();
        String username = request.getParameter("username");
        //username = username.replaceAll("'", ""); 可選定 '  並用空字串代替
        String tel = request.getParameter("tel");
        String birthday = request.getParameter("birthday");
        String sql="insert into person(username,tel,birthday) values('"+username+"','"+tel+"+','"+birthday+"')";//sql新增欄位資料語法
        System.out.println(sql);
        int x = st.executeUpdate(sql);//設定變數並執行新增一筆資料
        st.close();
        con.close();
    %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello insert2!</h1>
        新增<%=x%>筆 資料
        <a href="insert1.jsp">繼續新增</a>
        <a href="list.jsp">顯示清單</a>
    </body>
</html>
